//
//  CryptoOC.m
//  YiyaPuzzleDemo
//
//  Created by linhan on 16/10/24.
//  Copyright © 2016年 test. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "CryptoOC.h"
#include <CommonCrypto/CommonCrypto.h>
#import "QNUrlSafeBase64.h"

@implementation CryptoOC
    +(NSString*) hmac_sha1:(NSString *)text key:(NSString*)key
    {
        const char *cKey = [key cStringUsingEncoding:NSUTF8StringEncoding];
        const char *cData = [text cStringUsingEncoding:NSUTF8StringEncoding];
        
        char cHMAC[CC_SHA1_DIGEST_LENGTH];
        
        CCHmac(kCCHmacAlgSHA1, cKey, strlen(cKey), cData, strlen(cData), cHMAC);
        
        NSData *HMAC = [[NSData alloc] initWithBytes:cHMAC length:CC_SHA1_DIGEST_LENGTH];
        
        NSString *hash = [QNUrlSafeBase64 encodeData:HMAC];
        return hash;
    }
@end